﻿@using NewLife;
@using NewLife.Web;
@using XCode;
@using System.Linq;
@using Stardust.Data.Nodes;
@{
    var id = (Object)Model + "";
    var page = ViewBag.Page as Pager;

    if (id.IsNullOrEmpty()) { id = "nodeId"; }
    var nodeId = page[id];
    var showValue = Node.FindByID(nodeId.ToInt())?.Name;

    var set = NewLife.Cube.Setting.Current;
    var res = set.ResourceUrl;
    if (String.IsNullOrEmpty(res)) res = "/Content";
    res = res.TrimEnd('/');
}

<div class="form-group" style="position:relative">
    <div class="col-lg-12">
        <div class="input-group">
            <input type="hidden" name="@id" id="@id" value="@nodeId" />
            <input type="text" class="form-control" id="@(id)_select" placeholder="搜索节点" value="@showValue">
            <div class="input-group-btn">
                <ul class="dropdown-menu dropdown-menu-right" role="menu"></ul>
            </div>
        </div>
    </div>
</div>

<script src="@res/bootstrap-suggest.js"></script>
<script type="text/javascript">
    $(function () {
        $("#@(id)_select").bsSuggest({
            url: "/Nodes/Node/NodeSearch?key=",
            getDataMethod:"url",
            effectiveFieldsAlias: { ID: "编号", Code: "代码", Name: "名称", Category: "类别" },
            ignorecase: true,
            showHeader: true,
            delayUntilKeyup: true, //获取数据的方式为 firstByUrl 时，延迟到有输入/获取到焦点时才请求数据
            hideOnSelect: true,
            idField: "ID",
            showBtn: false,
            keyField: "Name",
            clearable: true,
            searchingTip: '搜索中...',
            allowNoKeyword: true,
            delay: 500,
            emptyTip: '无数据',
            containerValueId: '@id',
            fnProcessData: function (result) {
                dt = {};
                dt.value = result.data;
                return dt;
            }
        }).on('onSetSelectValue', function (e, keyword, data) {
            $('#@id').val(keyword.id);
        }).on('onUnsetSelectValue', function () {
            $('#@id').val('');
        });
    });
</script>